﻿// Decompiled with JetBrains decompiler
// Type: 我的小工具.frmAppConfig
// Assembly: 开发辅助工具, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null
// MVID: F78E5980-5E94-4E46-ABDF-DC8C6CBF52AA
// Assembly location: K:\Tools\工具\开发辅助工具庆六一版\开发辅助工具2015-06-01\开发辅助工具.exe

using System;
using System.ComponentModel;
using System.Configuration;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace 我的小工具
{
  public class frmAppConfig : Form
  {
    private IContainer components = (IContainer) null;
    private Button button1;
    private TextBox textBox1;
    private Label label1;
    private TextBox textBox2;
    private Label laber2;
    private Button button2;
    private Button button3;
    private Button button4;
    private Label label2;
    private TextBox textBox3;
    private Button button5;

    public frmAppConfig()
    {
      this.InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
      if (this.textBox1.Text.Length > 0 && !File.Exists(this.textBox1.Text))
      {
        int num = (int) MessageBox.Show(this.textBox1.Text + "不存在！");
        this.textBox1.Focus();
        this.textBox1.SelectAll();
      }
      else if (this.textBox2.Text.Length > 0 && !File.Exists(this.textBox2.Text))
      {
        int num = (int) MessageBox.Show(this.textBox2.Text + "不存在！");
        this.textBox2.Focus();
        this.textBox2.SelectAll();
      }
      else if (this.textBox3.Text.Length > 0 && !File.Exists(this.textBox3.Text))
      {
        int num = (int) MessageBox.Show(this.textBox3.Text + "不存在！");
        this.textBox3.Focus();
        this.textBox3.SelectAll();
      }
      else
      {
        try
        {
          System.Configuration.Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
          configuration.AppSettings.Settings["SSMSPATH"].Value = this.textBox1.Text;
          configuration.AppSettings.Settings["PROFILER"].Value = this.textBox2.Text;
          configuration.AppSettings.Settings["KSJMPATH"].Value = this.textBox3.Text;
          configuration.Save(ConfigurationSaveMode.Modified);
          ConfigurationManager.RefreshSection("appSettings");
          this.DialogResult = DialogResult.OK;
        }
        catch (Exception ex)
        {
          int num = (int) MessageBox.Show(ex.Message);
        }
      }
    }

    private void frmUserConfig_Load(object sender, EventArgs e)
    {
      this.textBox1.Text = ConfigurationManager.AppSettings["SSMSPATH"];
      this.textBox2.Text = ConfigurationManager.AppSettings["PROFILER"];
      this.textBox3.Text = ConfigurationManager.AppSettings["KSJMPATH"];
    }

    private string getFilePath(string initpath, string fileName)
    {
      OpenFileDialog openFileDialog = new OpenFileDialog();
      openFileDialog.InitialDirectory = Path.GetDirectoryName(initpath);
      openFileDialog.Filter = fileName + "|" + fileName;
      openFileDialog.FileName = fileName;
      openFileDialog.FilterIndex = 0;
      openFileDialog.RestoreDirectory = true;
      if (openFileDialog.ShowDialog() == DialogResult.OK)
        return openFileDialog.FileName;
      return (string) null;
    }

    private void button3_Click(object sender, EventArgs e)
    {
      string filePath = this.getFilePath(this.textBox1.Text, "Ssms.exe");
      if (filePath == null)
        return;
      this.textBox1.Text = filePath;
    }

    private void button4_Click(object sender, EventArgs e)
    {
      string filePath = this.getFilePath(this.textBox2.Text, "PROFILER.EXE");
      if (filePath == null)
        return;
      this.textBox1.Text = filePath;
    }

    private void button5_Click(object sender, EventArgs e)
    {
      string filePath = this.getFilePath(this.textBox3.Text, "DataBaseBuild.exe");
      if (filePath == null)
        return;
      this.textBox1.Text = filePath;
    }

    protected override void Dispose(bool disposing)
    {
      if (disposing && this.components != null)
        this.components.Dispose();
      base.Dispose(disposing);
    }

    private void InitializeComponent()
    {
      this.button1 = new Button();
      this.textBox1 = new TextBox();
      this.label1 = new Label();
      this.textBox2 = new TextBox();
      this.laber2 = new Label();
      this.button2 = new Button();
      this.button3 = new Button();
      this.button4 = new Button();
      this.label2 = new Label();
      this.textBox3 = new TextBox();
      this.button5 = new Button();
      this.SuspendLayout();
      this.button1.Location = new Point(447, 97);
      this.button1.Name = "button1";
      this.button1.Size = new Size(79, 23);
      this.button1.TabIndex = 3;
      this.button1.Text = "确定";
      this.button1.UseVisualStyleBackColor = true;
      this.button1.Click += new EventHandler(this.button1_Click);
      this.textBox1.Location = new Point(78, 14);
      this.textBox1.Name = "textBox1";
      this.textBox1.Size = new Size(488, 21);
      this.textBox1.TabIndex = 1;
      this.label1.AutoSize = true;
      this.label1.Location = new Point(7, 17);
      this.label1.Name = "label1";
      this.label1.Size = new Size(65, 12);
      this.label1.TabIndex = 2;
      this.label1.Text = "SSMSPATH：";
      this.textBox2.Location = new Point(78, 41);
      this.textBox2.Name = "textBox2";
      this.textBox2.Size = new Size(488, 21);
      this.textBox2.TabIndex = 2;
      this.laber2.AutoSize = true;
      this.laber2.Location = new Point(7, 44);
      this.laber2.Name = "laber2";
      this.laber2.Size = new Size(65, 12);
      this.laber2.TabIndex = 2;
      this.laber2.Text = "PROFILER：";
      this.button2.DialogResult = DialogResult.Cancel;
      this.button2.Location = new Point(532, 97);
      this.button2.Name = "button2";
      this.button2.Size = new Size(75, 23);
      this.button2.TabIndex = 4;
      this.button2.Text = "取消";
      this.button2.UseVisualStyleBackColor = true;
      this.button3.Location = new Point(572, 12);
      this.button3.Name = "button3";
      this.button3.Size = new Size(35, 23);
      this.button3.TabIndex = 5;
      this.button3.Text = "...";
      this.button3.UseVisualStyleBackColor = true;
      this.button3.Click += new EventHandler(this.button3_Click);
      this.button4.Location = new Point(572, 39);
      this.button4.Name = "button4";
      this.button4.Size = new Size(35, 23);
      this.button4.TabIndex = 5;
      this.button4.Text = "...";
      this.button4.UseVisualStyleBackColor = true;
      this.button4.Click += new EventHandler(this.button4_Click);
      this.label2.AutoSize = true;
      this.label2.Location = new Point(7, 72);
      this.label2.Name = "label2";
      this.label2.Size = new Size(65, 12);
      this.label2.TabIndex = 2;
      this.label2.Text = "快速建模：";
      this.textBox3.Location = new Point(78, 69);
      this.textBox3.Name = "textBox3";
      this.textBox3.Size = new Size(488, 21);
      this.textBox3.TabIndex = 2;
      this.button5.Location = new Point(572, 67);
      this.button5.Name = "button5";
      this.button5.Size = new Size(35, 23);
      this.button5.TabIndex = 5;
      this.button5.Text = "...";
      this.button5.UseVisualStyleBackColor = true;
      this.button5.Click += new EventHandler(this.button5_Click);
      this.AcceptButton = (IButtonControl) this.button1;
      this.AutoScaleDimensions = new SizeF(6f, 12f);
      this.AutoScaleMode = AutoScaleMode.Font;
      this.CancelButton = (IButtonControl) this.button2;
      this.ClientSize = new Size(620, 131);
      this.Controls.Add((Control) this.button5);
      this.Controls.Add((Control) this.button4);
      this.Controls.Add((Control) this.textBox3);
      this.Controls.Add((Control) this.button3);
      this.Controls.Add((Control) this.textBox2);
      this.Controls.Add((Control) this.label2);
      this.Controls.Add((Control) this.textBox1);
      this.Controls.Add((Control) this.laber2);
      this.Controls.Add((Control) this.button2);
      this.Controls.Add((Control) this.label1);
      this.Controls.Add((Control) this.button1);
      this.MaximizeBox = false;
      this.MinimizeBox = false;
      this.Name = "frmAppConfig";
      this.ShowIcon = false;
      this.StartPosition = FormStartPosition.CenterParent;
      this.Text = "设置";
      this.Load += new EventHandler(this.frmUserConfig_Load);
      this.ResumeLayout(false);
      this.PerformLayout();
    }
  }
}
